package com.joysuch.wwyt.edu.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.edu.bean.EduTrainTimeBean;
import com.joysuch.wwyt.edu.entity.EduExamRecord;
import com.joysuch.wwyt.edu.entity.EduTrainningRecordUser;
import com.joysuch.wwyt.edu.service.EduExamRecordService;
import com.joysuch.wwyt.edu.service.EduTrainningRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
@RequestMapping("/report-api/edu")
@Api(tags = "教育-培训")
public class EduReportController {

    @Autowired
    private EduTrainningRecordService eduTrainningRecordService;
    @Autowired
    private EduExamRecordService eduExamRecordService;


    /**
     *统计培训记录的学时
     * @param eduTrainTimeBean
     * @return
     */
    @GetMapping("trainTime")
    @ApiOperation(value = "培训记录的学时")
    public JSONObject userTrainTime(EduTrainTimeBean eduTrainTimeBean, Integer pageNo, Integer pageSize, HttpServletRequest request){

        IPage<EduTrainningRecordUser> eduTrainTimeBeanResults = eduTrainningRecordService.getUserTrainTime(eduTrainTimeBean, pageNo, pageSize);
        JSONObject object = new JSONObject();
        object.put("data", eduTrainTimeBeanResults.getRecords());
        object.put("total", (eduTrainTimeBeanResults.getTotal() + pageSize - 1)/pageSize);
        object.put("count", eduTrainTimeBeanResults.getRecords().size());
        return object;
    }

    /**
     * 考试记录的统计与导出
     * @param eduTrainTimeBean
     * @return
     */
    @GetMapping("testRecords")
    @ApiOperation(value = "考试记录的统计")
    public JSONObject testRecords(EduTrainTimeBean eduTrainTimeBean,Integer pageNo,Integer pageSize){
        IPage<EduExamRecord> eduExamRecordIPage = eduExamRecordService.queryExamRecords(eduTrainTimeBean,pageNo,pageSize);
        JSONObject object = new JSONObject();
        object.put("data", eduExamRecordIPage.getRecords());
        object.put("total", (eduExamRecordIPage.getTotal() + pageSize - 1)/pageSize);
        object.put("count", eduExamRecordIPage.getRecords().size());
        return object;
    }



}
